<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title></title>
    <meta name="renderer" content="webkit"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="format-detection" content="telephone=no"/>
    <link rel="stylesheet" href="/resource/common/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/resource/css/common.css" media="all"/>
</head>
<style>
    .layui-form-item {
        width: 350px;

    }
</style>
<body>
<blockquote class="layui-elem-quote layui-quote-nm">
    <div class="layui-form">
        <div class="layui-row " style="height: 50px;margin-top: 10px">

            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">教师：</label>
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <input name="userName" id="teacherName" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">学号：</label>
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <input name="userName" id="student" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label">学生：</label>
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <input name="userName" id="studentName" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-col-md2">
                <div class="layui-inline tableId" style="margin-top: -6px">
                    <button class="layui-btn layui-btn-normal" data-type="reload" id="search"><i class="layui-icon">&#xe615;</i>搜索
                    </button>
                    <button class="layui-btn layui-btn-normal" data-type="reload" id="revocation"><i
                            class="layui-icon">&#xe669;</i>撤销
                    </button>
                </div>
            </div>
        </div>

    </div>
</blockquote>
<script type="text/html" id="operate">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>

</script>
<table id="tables" lay-filter="tables" lay-skin="line"></table>
<!--<shiro:hasPermission name="button:student:index:edit">-->
<!--</shiro:hasPermission>-->
<script type="text/javascript" src="/resource/common/layui/layui.js"></script>
<script type="text/javascript" src=" /resource/js/user.js"></script>
<script type="text/javascript" th:inline="javascript">
    layui.use(['table', 'layer', 'laydate', 'form'], function () {
        var table = layui.table,
            $ = layui.$,
            layer = layui.layer,
            form = layui.form;
        var tableIns = table.render({
            elem: '#tables'
            , skin: 'line' //行边框风格
            , even: true //开启隔行背景
            , size: 'lg' //尺寸的表格
            , url: '/distribution/distribution.do' //数据接口
            , method: 'get'

            // ,where:{'sign':'score'}
            , toolbar: '#header'
            , page: true //开启分页
            , id: 'tableId'
            , limits: [10, 15, 30]
            , limit: 15
            , cols: [
                [ //表头

                    {field: 'student', title: '学号'}
                    , {field: 'studentName', title: '学生'}
                    // , {field: 'teacher', title: '工号'}
                    , {field: 'teacherName', title: '指导教师'}
                    , {field: 'name', title: '课题名称'}
                    , {field: 'score', title: '分数'}
                    , {title: '操作', toolbar: '#operate', 'fixed': 'right', width: 150}
                ]
            ]
        });
        //搜索
        $('#search').on('click', function () {
            console.log("搜索执行")
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        //撤销
        $("#revocation").on('click', function () {

            $("#teacherName").val('');
            $("#studentName").val('');
            $("#student").val('');
            form.render();
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : ''
        });
        table.on('toolbar(tables)', function (obj) {
            if (obj.event == "add") {
                //新增
                layer.open({
                    type: 2,
                    title: "添加",
                    maxmin: true,
                    shadeClose: true, //点击遮罩关闭层
                    area: ['600px', '400px'],
                    content: "/distribution/addPage.do"
                });
            }
        });
        //监听工具条
        table.on('tool(tables)', function (obj) {
            var data = obj.data;
            console.log(data);
            if(obj.event === 'detail'){
                closeBtn: 0,

                layer.open({

                    type: 1,
                    title: '<html><center ></html>'+'详细信息'+'<html></center></html>',
                    closeBtn: 0,
                    skin: 'layui-table', //样式类名
                    shadeClose: true,
                    area: '700px',
                    content:

                        '<html><table class="layui-table" ><center><thead> <tr><th></html>'+ '学号：'+'<html></th><th></html>'+ data.student +'<html></th></tr></html>'+
                        '<html><th></html>'+ '学生：'+'<html></th><th></html>'+ data.studentName +'<html></th></tr></html>'+
                        '<html><th></html>'+ '指导教师：'+'<html></th><th></html>'+ data.teacherName +'<html></th></tr></html>'+
                        '<html><th></html>'+ '课题名称：'+'<html></th><th></html>'+ data.name +'<html></th></tr></html>'+
                        '<html><th></html>'+ '分数：'+'<html></th><th></html>'+ data.score+'<html></th></tr> </thead></center></table></html>'

                });
            }
            if (obj.event === 'del') {
                //删除
                delEntity(data.id);
            } else if (obj.event === 'edit') {
                //删除
                layer.open({
                    type: 2,
                    title: "编辑",
                    maxmin: true,
                    shadeClose: true, //点击遮罩关闭层
                    area: ['100%', '100%'],
                    content: "/distribution/editPage.do?id=" + data.id
                });
            } else if (obj.event === 'yes') {
                editEntity(data.id, "确认通过")
            } else if (obj.event === 'no') {
                editEntity(data.id, "确认不通过")
            }
        });
        active = {
            reload: function () {

                var teacherName = $("#teacherName").val();
                var studentName = $("#studentName").val();
                var student = $("#student").val();
                //执行重载
                table.reload('tableId', {
                    page: {
                        curr: 1
                    }
                    , where: {

                        teacherName:teacherName,
                        studentName:studentName,
                        student: student,
                    }
                });
            }
        };

        //删除函数
        function delEntity(id) {
            layer.confirm('是否删除?', function (index) {
                $.ajax({
                    url: "/distribution/distribution.do",
                    type: "post",
                    data: {_method: "DELETE", "id": id},
                    dataType: "json",
                    success: function (result) {
                        if (!result.status) {
                            layer.msg(result.msg, {time: 2000});
                            return false;
                        }
                        layer.msg("删除成功!", {time: 1000});
                        active.reload();
                    }
                });
                layer.close(index);
            })
        }

        //删除函数
        function editEntity(id, state) {
            $.ajax({
                url: "/distribution/edit.do",
                type: "put",
                data: {"id": id, "state": state},
                dataType: "json",
                success: function (result) {
                    if (!result.status) {
                        layer.msg(result.msg, {time: 2000});
                        return false;
                    }
                    parent.layer.msg("操作成功!", {time: 1000});
                    active.reload();
                }
            });
        }
    });
</script>

</body>
</html>